<?php


    //excel导出操作 xls格式
    function upload_exl($data,$filename="demo.xls",$quarter=1,$title='铁路港报表'){
        ini_set('max_execution_time', '0');
        Vendor('PHPExcel.PHPExcel');
        $filename=str_replace('.xls', '', $filename).'.xls';
        $phpexcel = new PHPExcel();
        $phpexcel->getDefaultStyle()->getFont()->setName('微软雅黑');
        $phpexcel->getDefaultStyle()->getFont()->setSize(14);
        if ($quarter!=1){
            $quarter='1-'.$quarter;
        }
/*        $phpexcel->getDefaultStyle()->getFont()->setBold(true);*/
        $phpexcel->getProperties()
            ->setCreator("Maarten Balliauw")
            ->setLastModifiedBy("Maarten Balliauw")
            ->setTitle("Office 2007 XLSX Test Document")
            ->setSubject("Office 2007 XLSX Test Document")
            ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
            ->setKeywords("office 2007 openxml php")
            ->setCategory("Test result file");
        $arr1 = ['指标名称','计量单位','代码','上年'.$quarter.'季度','本年'.$quarter.'季度'];
        $arr2 = ['甲','乙','丙','1','2'];
        $arr3 = [$title];
        array_unshift($data,$arr3,$arr1,$arr2);
        $n = count($data);
        $phpexcel->getActiveSheet()->getStyle('A1:E'.$n)->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);//设置边框
//合并单元格
        $phpexcel->getActiveSheet()->mergeCells( 'A1:E1');
        //设置行的高度
        $phpexcel->getActiveSheet()->getRowDimension('1')->setRowHeight(80);
        //单元格内容水平居中
        $phpexcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        //单元格内容垂直居中
        $phpexcel->getActiveSheet()->getStyle('A1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        //设置字体大小
        $phpexcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(20);
        $phpexcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);

        //设置单元格宽度
        $phpexcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
        $phpexcel->getActiveSheet()->getColumnDimension('D')->setWidth(25);
        $phpexcel->getActiveSheet()->getColumnDimension('E')->setWidth(25);
/*        $phpexcel->getActiveSheet()->getStyle('D')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);*/
        /*        $phpexcel->getActiveSheet()->getProtection()->setSheet(true);  // 为了使任何表保护，需设置为真
                $phpexcel->getActiveSheet()->protectCells( 'A1:B1:C1:D1:E1:F1', 'PHPExcel' ); // 将A3到E13保护 加密密码是 PHPExcel*/
        $phpexcel->getActiveSheet()->fromArray($data);
        $phpexcel->getActiveSheet()->setTitle('Sheet2');
        $phpexcel->setActiveSheetIndex(0);
        header('Content-Type: application/vnd.ms-excel');
        header("Content-Disposition: attachment;filename=$filename");
        header('Cache-Control: max-age=0');
        header('Cache-Control: max-age=1');
        header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
        header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
        header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
        header ('Pragma: public'); // HTTP/1.0
        $objwriter = PHPExcel_IOFactory::createWriter($phpexcel, 'Excel5');
        $objwriter->save('php://output');
        exit;
    }

        //excel导出操作 xls格式
    function wuliu_upload($data,$filename="demo.xls",$quarter=1,$title='铁路港报表'){
        ini_set('max_execution_time', '0');
        Vendor('PHPExcel.PHPExcel');
        $filename=str_replace('.xls', '', $filename).'.xls';
        $phpexcel = new PHPExcel();
        $phpexcel->getDefaultStyle()->getFont()->setName('微软雅黑');
        $phpexcel->getDefaultStyle()->getFont()->setSize(10);
        if ($quarter!=1){
            $quarter='1-'.$quarter;
        }
/*        $phpexcel->getDefaultStyle()->getFont()->setBold(true);*/
        $phpexcel->getProperties()
            ->setCreator("Maarten Balliauw")
            ->setLastModifiedBy("Maarten Balliauw")
            ->setTitle("Office 2007 XLSX Test Document")
            ->setSubject("Office 2007 XLSX Test Document")
            ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
            ->setKeywords("office 2007 openxml php")
            ->setCategory("Test result file");
        $arr1 = ['企业名称','行业类型','基本情况','','','','','','','','','','','','','','','','','','','','','','','仓储配送量','','','','','仓储配送装备','','','','','','','','','','','货代业务','','','','','','','','重点物流企业人力资源','','','','','',''];
        $arr2 = ['','','从业人员数(人)','','','','营业收入(万元)','','','','货运总量(吨)','','','','','货运周转量（吨/公里）','','','','','集装箱吞吐量（标准箱）','','','','','','','','','','仓储面积（平方米）','','','集装箱堆场面积（平方米）','','','仓库类型（平方米）','','','','','货代业务票数（票）','','','','货代业务量（吨）','','','','大专以上学历员工数（人）','','','高中及以下员工数（人）','持有物流相关专业大专以上员工数','持有物流师资格认证或相关执业资格员工数','接受过物流培训员工数'];
        $arr4 = ['','','其中：运输企业人数','其中：仓储配送企业','其中：货运代理企业','其中：物流专业市场','其中：运输企业收入','其中：仓储配送企业','其中：货运代理企业','其中：物流专业市场','合计','其中：出口内贸','其中：出口外贸','其中：进口内贸','其中：进口外贸','合计','其中：出口内贸','其中：出口外贸','其中：进口内贸','其中：进口外贸','合计','其中：出口内贸','其中：出口外贸','其中：进口内贸','其中：进口外贸','平均库存量（吨）','入库总量（吨）','出库总量（吨）','配送量（吨或包裹数）','配送频率（次/月）','合计','其中：自有仓库面积','其中：租用仓库面积','合计','其中：自有堆场','其中：租用堆场','类型','普通仓面积','立体仓容积','冷库容积','托盘规格标准化（A:1200*1000MM B:1100*1100mm C:其他）','货代订舱服务','进出口报关服务','进出口报检服务','无船承运人','货代订舱服务','进出口报关服务','进出口报检服务','无船承运人','合计','本科以上','专科','','','',''];
        $arr3 = [$title];
        array_unshift($data,$arr3,$arr1,$arr2,$arr4);
        $n = count($data);
        $phpexcel->getActiveSheet()->getStyle('A1:BD'.$n)->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);//设置边框
//合并单元格
        $phpexcel->getActiveSheet()->mergeCells( 'A1:BD1');
        $phpexcel->getActiveSheet()->mergeCells( 'A2:A4');
        $phpexcel->getActiveSheet()->mergeCells( 'B2:B4');
        $phpexcel->getActiveSheet()->mergeCells( 'C2:Y2');
        $phpexcel->getActiveSheet()->mergeCells( 'Z2:AD3');
        $phpexcel->getActiveSheet()->mergeCells( 'AE2:AO2');
        $phpexcel->getActiveSheet()->mergeCells( 'AP2:AW2');
        $phpexcel->getActiveSheet()->mergeCells( 'AX2:BD2');
        $phpexcel->getActiveSheet()->mergeCells( 'C3:F3');
        $phpexcel->getActiveSheet()->mergeCells( 'G3:J3');
        $phpexcel->getActiveSheet()->mergeCells( 'K3:O3');
        $phpexcel->getActiveSheet()->mergeCells( 'P3:T3');
        $phpexcel->getActiveSheet()->mergeCells( 'U3:Y3');
        $phpexcel->getActiveSheet()->mergeCells( 'AE3:AG3');
        $phpexcel->getActiveSheet()->mergeCells( 'AH3:AJ3');
        $phpexcel->getActiveSheet()->mergeCells( 'AK3:AO3');
        $phpexcel->getActiveSheet()->mergeCells( 'AP3:AS3');
        $phpexcel->getActiveSheet()->mergeCells( 'AX3:AZ3');
        $phpexcel->getActiveSheet()->mergeCells( 'AT3:AW3');
        $phpexcel->getActiveSheet()->mergeCells( 'BA3:BA4');
        $phpexcel->getActiveSheet()->mergeCells( 'BB3:BB4');
        $phpexcel->getActiveSheet()->mergeCells( 'BC3:BC4');
        $phpexcel->getActiveSheet()->mergeCells( 'BD3:BD4');
        //设置行的高度
        $phpexcel->getActiveSheet()->getRowDimension('1')->setRowHeight(40);
        //单元格内容水平居中
        $phpexcel->getActiveSheet()->getStyle('A1:BD'.$n)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        //单元格内容垂直居中
        $phpexcel->getActiveSheet()->getStyle('A1:BD'.$n)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        //设置字体大小
        $phpexcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(15);
        $phpexcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
        $celllist=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AO','AP','AQ','AR','AS','AT','AU','AV','AW','AX','AY','AZ','BA','BB','BC','BD'];
        foreach ($celllist as $value) {
                    //设置单元格宽度
            $phpexcel->getActiveSheet()->getColumnDimension($value)->setWidth(20);
        }


/*        $phpexcel->getActiveSheet()->getStyle('D')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);*/
        /*        $phpexcel->getActiveSheet()->getProtection()->setSheet(true);  // 为了使任何表保护，需设置为真
                $phpexcel->getActiveSheet()->protectCells( 'A1:B1:C1:D1:E1:F1', 'PHPExcel' ); // 将A3到E13保护 加密密码是 PHPExcel*/
        $phpexcel->getActiveSheet()->fromArray($data);
        $phpexcel->getActiveSheet()->setTitle('Sheet2');
        $phpexcel->setActiveSheetIndex(0);
        header('Content-Type: application/vnd.ms-excel');
        header("Content-Disposition: attachment;filename=$filename");
        header('Cache-Control: max-age=0');
        header('Cache-Control: max-age=1');
        header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
        header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
        header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
        header ('Pragma: public'); // HTTP/1.0
        $objwriter = PHPExcel_IOFactory::createWriter($phpexcel, 'Excel5');
        $objwriter->save('php://output');
        exit;
    }


        function gongye_upload($data,$filename="demo.xls",$quarter=1,$title='铁路港报表'){
        ini_set('max_execution_time', '0');
        Vendor('PHPExcel.PHPExcel');
        $filename=str_replace('.xls', '', $filename).'.xls';
        $phpexcel = new PHPExcel();
        $phpexcel->getDefaultStyle()->getFont()->setName('微软雅黑');
        $phpexcel->getDefaultStyle()->getFont()->setSize(10);
        if ($quarter!=1){
            $quarter='1-'.$quarter;
        }
/*        $phpexcel->getDefaultStyle()->getFont()->setBold(true);*/
        $phpexcel->getProperties()
            ->setCreator("Maarten Balliauw")
            ->setLastModifiedBy("Maarten Balliauw")
            ->setTitle("Office 2007 XLSX Test Document")
            ->setSubject("Office 2007 XLSX Test Document")
            ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
            ->setKeywords("office 2007 openxml php")
            ->setCategory("Test result file");
        $arr1 = ['企业名称','基本情况','','','','先进材料','','','','','智能装备','','','','','产品销售','','','','原材料供应','','','','科技创新','','','','','','','','',''];
        $arr2 = ['','从业人员数(人)','产值','主营业务收入','主营业务成本','行业类型','从业人员数','产值','主营业务收入','主营业务成本','行业类型','从业人员数','产值','主营业务收入','主营业务成本','产品类别','产品销售收入','产品销售地','产品出口地','原材料类别','原材料采购量','原材料供应地（国内）','原材料供应地（国外）','专利数量','','','','技术研发机构','','','','品牌建设','','',''];
        $arr4 = ['','','','','','','','','','','','','','','','','','','','','','','','合计','发明专利','实用新型专利','外观设计专利','合计','国家级','省级','市级','合计','国家级','省级','市级'];
        $arr3 = [$title];
        array_unshift($data,$arr3,$arr1,$arr2,$arr4);
        $n = count($data);
        $phpexcel->getActiveSheet()->getStyle('A1:AI'.$n)->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);//设置边框
//合并单元格
        $phpexcel->getActiveSheet()->mergeCells( 'A1:AI1');
        $phpexcel->getActiveSheet()->mergeCells( 'A2:A4');
        $phpexcel->getActiveSheet()->mergeCells( 'B2:E2');
        $phpexcel->getActiveSheet()->mergeCells( 'F2:J2');
        $phpexcel->getActiveSheet()->mergeCells( 'K2:O2');
        $phpexcel->getActiveSheet()->mergeCells( 'P2:S2');
        $phpexcel->getActiveSheet()->mergeCells( 'T2:W2');
        $phpexcel->getActiveSheet()->mergeCells( 'X2:AI2');

        $PPARR=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W'];
        foreach ($PPARR as $value) {
            $phpexcel->getActiveSheet()->mergeCells( $value.'3:'.$value.'4');
        }
        $phpexcel->getActiveSheet()->mergeCells( 'X3:AA3');
        $phpexcel->getActiveSheet()->mergeCells( 'AB3:AE3');
        $phpexcel->getActiveSheet()->mergeCells( 'AF3:AI3');
        //设置行的高度
        $phpexcel->getActiveSheet()->getRowDimension('1')->setRowHeight(40);
        //单元格内容水平居中
        $phpexcel->getActiveSheet()->getStyle('A1:AI'.$n)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        //单元格内容垂直居中
        $phpexcel->getActiveSheet()->getStyle('A1:AI'.$n)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        //设置字体大小
        $phpexcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(15);
        $phpexcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
        $celllist=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI'];
        foreach ($celllist as $value) {
                    //设置单元格宽度
            $phpexcel->getActiveSheet()->getColumnDimension($value)->setWidth(20);
        }

        $phpexcel->getActiveSheet()->fromArray($data);
        $phpexcel->getActiveSheet()->setTitle('Sheet2');
        $phpexcel->setActiveSheetIndex(0);
        header('Content-Type: application/vnd.ms-excel');
        header("Content-Disposition: attachment;filename=$filename");
        header('Cache-Control: max-age=0');
        header('Cache-Control: max-age=1');
        header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
        header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
        header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
        header ('Pragma: public'); // HTTP/1.0
        $objwriter = PHPExcel_IOFactory::createWriter($phpexcel, 'Excel5');
        $objwriter->save('php://output');
        exit;
    }

        function maoyi_upload($data,$filename="demo.xls",$quarter=1,$title='铁路港报表'){
        ini_set('max_execution_time', '0');
        Vendor('PHPExcel.PHPExcel');
        $filename=str_replace('.xls', '', $filename).'.xls';
        $phpexcel = new PHPExcel();
        $phpexcel->getDefaultStyle()->getFont()->setName('微软雅黑');
        $phpexcel->getDefaultStyle()->getFont()->setSize(10);
        if ($quarter!=1){
            $quarter='1-'.$quarter;
        }
/*        $phpexcel->getDefaultStyle()->getFont()->setBold(true);*/
        $phpexcel->getProperties()
            ->setCreator("Maarten Balliauw")
            ->setLastModifiedBy("Maarten Balliauw")
            ->setTitle("Office 2007 XLSX Test Document")
            ->setSubject("Office 2007 XLSX Test Document")
            ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
            ->setKeywords("office 2007 openxml php")
            ->setCategory("Test result file");
        $arr1 = ['企业名称','行业类型','基本情况','','','商品销售','','','','','','','','','','','商品采购','','','','','','','','','电子商务平台','','','','','','','','',''];
        $arr2 = ['','','从业人员数(人)','主营业务收入（万元）','主营业务成本（万元）','年销售额（万元）','零售额（万元）','商品销售地（国内）','','','商品销售地（国外）','','','商品分类','','','商品采购地（国内）','','','商品采购地（国外）','','','商品分类','','','运营企业数（家）','从业人员数（人）','主营业务收入（万元）','电商平台交易额（万元）','电商平台交易覆盖国家（个）','覆盖国家的名称','仓库面积（平方米）','自用面积（平方米）','租用面积（平方米）','剩余面积（平方米）'];
        $arr4 = ['','','','','','','','地点','销售量','销售金额','地点','销售量','销售金额','分类','销售量','销售金额','地点','采购量','采购金额','地点','采购量','采购金额','分类','采购量','采购金额','','','','','','','','','',''];
        $arr3 = [$title];
        array_unshift($data,$arr3,$arr1,$arr2,$arr4);
        $n = count($data);
        $phpexcel->getActiveSheet()->getStyle('A1:AI'.$n)->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);//设置边框
//合并单元格
        $phpexcel->getActiveSheet()->mergeCells( 'A1:AI1');
        $phpexcel->getActiveSheet()->mergeCells( 'A2:A4');
        $phpexcel->getActiveSheet()->mergeCells( 'B2:B4');
        $phpexcel->getActiveSheet()->mergeCells( 'C2:E2');
        $phpexcel->getActiveSheet()->mergeCells( 'F2:P2');
        $phpexcel->getActiveSheet()->mergeCells( 'Q2:Y2');
        $phpexcel->getActiveSheet()->mergeCells( 'Z2:AI2');

        $PPARR=['C','D','E','F','G','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI'];
        foreach ($PPARR as $value) {
            $phpexcel->getActiveSheet()->mergeCells( $value.'3:'.$value.'4');
        }

        $phpexcel->getActiveSheet()->mergeCells( 'H3:J3');
        $phpexcel->getActiveSheet()->mergeCells( 'K3:M3');
        $phpexcel->getActiveSheet()->mergeCells( 'N3:P3');
        $phpexcel->getActiveSheet()->mergeCells( 'Q3:S3');
        $phpexcel->getActiveSheet()->mergeCells( 'T3:V3');
        $phpexcel->getActiveSheet()->mergeCells( 'W3:Y3');
        //设置行的高度
        $phpexcel->getActiveSheet()->getRowDimension('1')->setRowHeight(40);
        //单元格内容水平居中
        $phpexcel->getActiveSheet()->getStyle('A1:AI'.$n)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        //单元格内容垂直居中
        $phpexcel->getActiveSheet()->getStyle('A1:AI'.$n)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        //设置字体大小
        $phpexcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(15);
        $phpexcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
        $celllist=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI'];
        foreach ($celllist as $value) {
                    //设置单元格宽度
            $phpexcel->getActiveSheet()->getColumnDimension($value)->setWidth(20);
        }

        $phpexcel->getActiveSheet()->fromArray($data);
        $phpexcel->getActiveSheet()->setTitle('Sheet2');
        $phpexcel->setActiveSheetIndex(0);
        header('Content-Type: application/vnd.ms-excel');
        header("Content-Disposition: attachment;filename=$filename");
        header('Cache-Control: max-age=0');
        header('Cache-Control: max-age=1');
        header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
        header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
        header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
        header ('Pragma: public'); // HTTP/1.0
        $objwriter = PHPExcel_IOFactory::createWriter($phpexcel, 'Excel5');
        $objwriter->save('php://output');
        exit;
    }


    //excel 导入操作
    function add_exl($file){
        // 判断文件是什么格式
        $type = pathinfo($file);
        $type = strtolower($type["extension"]);
        if ($type=='xlsx') {
            $type='Excel2007';
        }elseif($type=='xls') {
            $type = 'Excel5';
        }
        ini_set('max_execution_time', '0');
        Vendor('PHPExcel.PHPExcel');
        // 判断使用哪种格式
        $objReader = PHPExcel_IOFactory::createReader($type);
        $objPHPExcel = $objReader->load($file);
        $sheet = $objPHPExcel->getSheet(0);
        // 取得总行数
        $highestRow = $sheet->getHighestRow();
        // 取得总列数
        $highestColumn = $sheet->getHighestColumn();
        //循环读取excel文件,读取一条,插入一条
        $data=array();
        //从第几行开始读取数据
        for($j=4;$j<=$highestRow;$j++){
            //从A列读取数据
            for($k='A';$k<=$highestColumn;$k++){
                // 读取单元格
                $data[$j][]=$objPHPExcel->getActiveSheet()->getCell("$k$j")->getValue();
            }
        }
        return $data;
    }

	function p ($array){
		dump($array,1,'<pre>',0);	
	}

	function get_avatar_name(){
		return 'temp';
	}
	
    function sendMail($to, $title, $content) {
     
        Vendor('PHPMailer.PHPMailerAutoload');     
        $mail = new PHPMailer(); //实例化
        $mail->IsSMTP(); // 启用SMTP
        $mail->Host=C('MAIL_HOST'); //smtp服务器的名称（这里以QQ邮箱为例）
        $mail->SMTPAuth = C('MAIL_SMTPAUTH'); //启用smtp认证
        $mail->Username = C('MAIL_USERNAME'); //你的邮箱名
        $mail->Password = C('MAIL_PASSWORD') ; //邮箱密码
        $mail->From = C('MAIL_FROM'); //发件人地址（也就是你的邮箱地址）
        $mail->FromName = C('MAIL_FROMNAME'); //发件人姓名
        $mail->AddAddress($to,"尊敬的客户");
        $mail->WordWrap = 50; //设置每行字符长度
        $mail->IsHTML(C('MAIL_ISHTML')); // 是否HTML格式邮件
        $mail->CharSet=C('MAIL_CHARSET'); //设置邮件编码
        $mail->Subject =$title; //邮件主题
        $mail->Body = $content; //邮件内容
        $mail->AltBody = ""; //邮件正文不支持HTML的备用显示
        return($mail->Send());
    }

    function subtext($text, $length)
    {
    	if(mb_strlen($text, 'utf8') > $length)
    		return mb_substr($text, 0, $length, 'utf8').'...';
    	return $text;
    }
    
/**************************数据备份操作*****************************/

    /**
    * 格式化字节大小
    * @param  number $size      字节数
    * @param  string $delimiter 数字和单位分隔符
    * @return string            格式化后的带单位的大小
    * @author slackck <876902658@qq.com>
    */
    function format_bytes($size, $delimiter = '') {
    $units = array(' B', ' KB', ' MB', ' GB', ' TB', ' PB');
    		for ($i = 0; $size >= 1024 && $i < 5; $i++) $size /= 1024;
    		return round($size, 2) . $delimiter . $units[$i];
    }
    
/******************************保存图片到本地***********************************/
    function getImage($url,$save_dir='',$filename='',$type=0){
    	if(trim($url)==''){
    		return array('file_name'=>'','save_path'=>'','error'=>1);
    	}
    	if(trim($save_dir)==''){
    		$save_dir='./';
    	}
    	if(trim($filename)==''){//保存文件名
    		$ext=strrchr($url,'.');
    		if($ext!='.gif'&&$ext!='.jpg'&&$ext!='.png'&&$ext!='.jpeg'){
    			return array('file_name'=>'','save_path'=>'','error'=>3);
    		}
    		$filename=time().rand(0,10000).$ext;
    	}
    	if(0!==strrpos($save_dir,'/')){
    		$save_dir.='/';
    	}
    	//创建保存目录
    	if(!file_exists($save_dir)&&!mkdir($save_dir,0777,true)){
    		return array('file_name'=>'','save_path'=>'','error'=>5);
    	}
    	//获取远程文件所采用的方法
    	if($type){
    		$ch=curl_init();
    		$timeout=5;
    		curl_setopt($ch,CURLOPT_URL,$url);
    		curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    		curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
    		$img=curl_exec($ch);
    		curl_close($ch);
    	}else{
    		ob_start();
    		readfile($url);
    		$img=ob_get_contents();
    		ob_end_clean();
    	}
    	//$size=strlen($img);
    	//文件大小
    	$fp2=@fopen($save_dir.$filename,'a');
    	fwrite($fp2,$img);
    	fclose($fp2);
    	unset($img,$url);
    	return array('file_name'=>$filename,'save_path'=>$save_dir.$filename,'error'=>0);
    }
?>